home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6324 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: gail.ripco.com!mambuhl
  2. From: mambuhl@ripco.com (Martin Ambuhl)
  3. Newsgroups: comp.lang.c
  4. Subject: returning ptr to struct w
  5. Date: 23 Feb 1996 18:49:34 GMT
  6. Organization: Ripco Communications, Inc.
  7. Message-ID: <4gl27u$dh3@gail.ripco.com>
  8. NNTP-Posting-Host: foley.ripco.com
  9.  
  10. lbona@saratoga (lbona)
  11. in <4gk852INNbp4@faatcrl.faa.gov> writes:
  12.  
  13.  
  14. >When I declare a function that returns a pointer to a struct that contains
  15. >pointers, the pointer(s) at the end of the struct get set to garbage after
  16. >being returned. Pointers not at the end are not affected.
  17.  
  18.  [snip]
  19.  
  20. >typedef struct bar {
  21. >  long a;
  22. >  long b;
  23. >  int c;
  24. >  AAA *d;
  25. >  char e;
  26. >  char f[100];
  27. >  AAA *g;
  28. >  AAA *h;
  29. >} BAR;
  30.  
  31. >main()
  32. >{
  33. >BAR BB;
  34. >char toke[128];
  35.  
  36. >  memset(&BB,0,sizeof(BAR));
  37. >   /* at this point BB.d == BB.g == BB.h == NULL */
  38.  
  39.  [snip]
  40.  
  41. I apologize for not checking the rest of your code, but we need to stop
  42. and take stock here.  While the contents BB.d, BB.g, and BB.h are all
  43. zero, there is _no_ guarantee that the null pointer (or floating point
  44. zero) have such a representation.  If you depend on these being NULL,
  45. then you should set them explicitly.
  46.  
  47.                                  
  48. --
  49. * Martin Ambuhl       net: mambuhl@ripco.com
  50. * Chicago, IL (USA)    
  51.